import sys
def main():
    fileName = sys.argv[1]
    context = ""
    with open(fileName) as file_obj:
        tmp = file_obj.read()
        context += tmp
    reader = Reader(context)
    type = getType(reader)
    while type != None:
        print(type)
        if(type == 'Unknown'):
            break
        type = getType(reader)


def getType(reader):
    reader.skip()
    char = reader.getchar()

    if char == None:
        return None

    if char.isalpha():
        token = ""
        while char.isalpha() or char.isdigit():
            token += char
            char = reader.getchar()
        reader.ungetc()
        key = getReserve(token)
        if key == 0:
            return ("Ident(%s)"%token)
        else:
            return (key)
    elif char.isdigit():
        token = ""
        while char != None and char.isdigit():
            token += char
            char = reader.getchar()
        reader.ungetc()
        return("Int(%d)"%((int)(token)))
    elif char == '+':
        return ('Plus')
    elif char == '*':
        return ('Star')
    elif char == ',':
        return ('Comma')
    elif char == '(':
        return ('LParenthesis')
    elif char == ')':
        return ('RParenthesis')
    elif char == ':':
        char = reader.getchar()
        if char == '=':
            return ('Assign')
        reader.ungetc()
        return ('Colon')
    if(reader.getchar() == None) :
        return None
    return ('Unknown')

# 保留字
def getReserve(token):
    reserves = {'BEGIN': "Begin", 'END': "End", 'FOR': 'For',\
        'IF': 'If', 'THEN': 'Then', 'ELSE': 'Else'}
    if token in reserves:
        return reserves[token]
    return 0

# 读取类，可以读入字符，退出字符等
class Reader:
    def __init__(self, chars):
        self.chars = chars
        self.index = 0

    def getchar(self):
        if self.index == len(self.chars):
            return None
        self.index += 1
        return self.chars[self.index - 1]

    def ungetc(self):
        if self.index == 0:
            return False
        self.index -= 1
        return True

    def skip(self):
        char = self.getchar()
        if char == None:
            return
        white = " \n\r\t"
        while char != None and white.find(char) != -1:
            char = self.getchar()
        self.ungetc()


if __name__ == "__main__":
    main()
